﻿using System;
using System.Collections.Generic;
using System.Text;
using UmlDesigner.Model;
using System.IO;
using System.Windows.Forms;

namespace UmlDesigner.Gui
{
    struct UmlClipboardData
    {
        static private string clipboardFormatTag = "UDFDATA";

        static internal void CopyToClipboard(List<ItemWidget> items)
        {
            MemoryStream s = new MemoryStream();
            Document d = new Document();
            d.items = items;
            ModelSerializer ms = new ModelSerializer();
            Storage storage = Storage.BeginSave(s);
            ms.Save(d, storage);
            storage.Close();

            Clipboard.SetData(clipboardFormatTag, s.ToArray());
        }

        static internal Document CreateFromClipboard()
        {
            if (Clipboard.GetDataObject().GetDataPresent(clipboardFormatTag))
            {
                byte[] data = (byte[])Clipboard.GetDataObject().GetData(clipboardFormatTag);

                MemoryStream s = new MemoryStream(data);
                ModelSerializer ms = new ModelSerializer();
                Document d = new Document();
                ms.Load(d, Storage.Open(s));

                return d;
            }
            return null;
        }
    }
}
